package cn.sciento.farm.devicemanager.api.jsonrpc.impl;

import cn.sciento.farm.devicemanager.api.jsonrpc.CollectionTypeJsonApi;
import cn.sciento.farm.devicemanager.common.constant.ResultConstant;
import cn.sciento.farm.devicemanager.common.util.ReturnUtil;
import cn.sciento.farm.devicemanager.dao.entity.DevCollection;
import cn.sciento.farm.devicemanager.dao.entity.DevCollectionType;
import cn.sciento.farm.devicemanager.dao.model.ResponseMessage;
import cn.sciento.farm.devicemanager.gateway.model.uplink.CollectionType;
import cn.sciento.farm.devicemanager.service.CollectionTypeService;
import com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AutoJsonRpcServiceImpl
public class CollectionTypeJsonApiImpl implements CollectionTypeJsonApi {

    @Autowired
    CollectionTypeService collectionTypeService;

    @Override
    public ResponseMessage add(DevCollectionType collectionType) {
        int count = collectionTypeService.add(collectionType);
        return ReturnUtil.getReturnMap(ResultConstant.SUCCESS, count);
    }

    @Override
    public ResponseMessage update(DevCollectionType collectionType) {
        int count = collectionTypeService.updateById(collectionType);
        return ReturnUtil.getReturnMap(ResultConstant.SUCCESS, count);
    }

    @Override
    public ResponseMessage list() {
        List<DevCollectionType> collectionTypeList = collectionTypeService.list();
        return ReturnUtil.getReturnMap(ResultConstant.SUCCESS, collectionTypeList);
    }

    @Override
    public ResponseMessage get(String type) {
        DevCollectionType collectionType = collectionTypeService.getById(type);
        return ReturnUtil.getReturnMap(ResultConstant.SUCCESS, collectionType);
    }
}
